using System;
using System.IO;

namespace Framework
{
    public interface IFileSystem
    {
        public bool LoadFileEnable();
        public bool IsDirectory(string path);
        public bool Exists(string path);
        public void Delete(string path);
        public void CreateDirectory(string path);
        public void WriteAllBytes(string path, byte[] buffer, int offset = 0, int length = 0);
        public void WriteAllText(string path, string contents);
        public string[] GetFileSystemEntries(string path);
        public byte[] ReadFile(string path);
    }
    public class DefaultFileSystem : IFileSystem
    {

        public void CreateDirectory(string path)
        {
            Directory.CreateDirectory(path);
        }

        public void Delete(string path)
        {
            if (IsDirectory(path))
            {
                Directory.Delete(path, true);
            }
            else
            {
                File.Delete(path);
            }
        }

        public bool Exists(string path)
        {
            if (IsDirectory(path))
            {
                return Directory.Exists(path);
            }
            return File.Exists(path);
        }

        public string[] GetFileSystemEntries(string path)
        {
            return Directory.GetFileSystemEntries(path);
        }

        public bool LoadFileEnable()
        {
            return true;
        }

        public bool IsDirectory(string path)
        {
            return Directory.Exists(path);

        }

        public void WriteAllBytes(string path, byte[] buffer, int offset = 0, int length = 0)
        {
            File.WriteAllBytes(path, buffer);
        }

        public void WriteAllText(string path, string contents)
        {
            File.WriteAllText(path, contents);
        }
        public byte[] ReadFile(string path)
        {
            return File.ReadAllBytes(path);
        }
    }
}